#ifndef ObjectVisitor_h__
#define ObjectVisitor_h__

#include "IObjectVisitor.h"

#include "Path.h"

namespace tinyxml2
{
	class XMLDocument;
	class XMLElement;
}

namespace le
{
	enum EObjectType
	{
		eObjectType_Int32 = 0,
		eObjectType_Float = 1,
		eObjectType_String = 2,
	};

	class ObjectVisitor: public IObjectVisitor
	{
	public:
		ObjectVisitor();
		virtual ~ObjectVisitor();

		bool Load(const char* fileName);
		bool Load(const le::Path& fileName);
		bool Save(const char* fileName);
		bool IsReading() const {return m_IsReading;}
		void MarkForWriting();

		bool EnterNode(const char* nodeName);
		bool ExitNode();
		int32 GetCount(const char* nodeName) const;

		bool Visit(const char* name, int32& value, const int32 defaultValue);
		bool Visit(const char* name, float& value, const float defaultValue);
		bool Visit(const char* name, std::string& value, const std::string& defaultValue);

	private:
		void Reset();
		template <class T>
		bool Visit(const char* name, T& value, const T& defaultValue, EObjectType type);

	private:
		bool m_IsReading;
		tinyxml2::XMLDocument* m_XmlDoc;
		tinyxml2::XMLElement* m_CurrentXmlElement;
		tinyxml2::XMLElement* m_SibblingElement;
	};
}

#include "ObjectVisitor.inl"

#endif // ObjectVisitor_h__